
import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

// 简单的应用
// state (全局变量的数据)
// getters (用来获取数据的方法)
// actions (跟后台接口打交道的方法)
// mutations (存储数据的方法)

// vueComponent(组件) -> actions 
// -> mutations -> state -> vueComponent(组件)

// vueComponent(组件) -> getters -> state

let store = new Vuex.Store({
	// 1. state
	state: {
		userInfo: '',
		TravalPagelist: '',
		DebtReimNotelist: '',
		SaveDataBaoxiao: '',
		OctDataList: '',
		OverWorkList: '',
		SaveOverWork: '',
		//主表
		mainData: '',
		//字表
		BaseData: ''
	},

	// // 2. getters
	getters: {
		// 参数列表state指的是state数据
		getUserInfo(state) {
			return state.userInfo;
		},
		getTravalPagelist(state) {
			return state.TravalPagelist;
		},
		getDebtReimNotelist(state) {
			return state.DebtReimNotelist;
		},
		getSaveDataBaoxiao(state) {
			return state.SaveDataBaoxiao;
		},
		getOctDataList(state) {
			return state.OctDataList;
		},
		getOverWorkList(state) {
			// debugger
			return state.OverWorkList;
		},
		getSaveOverWork(state) {
			return state.SaveOverWork;
		},
		//获取主表

		//获取字表
		getBaseData(state) {
			return state.BaseData;
		}
	},
	// 3. actions
	// 通常跟api接口打交道
	actions: {
		// 设置城市信息
		// 参数列表：{commit, state}
		// state指的是state数据
		// commit调用mutations的方法 
		// name就是调用此方法时要传的参数
		setUserInfo({ commit, state }, name) {
			// 跟后台打交道
			// 调用mutaions里面的方法
			commit("setInfo", name);
		},
		setTravalPagelist({ commit, state }, name) {
			commit('setTravalPage', name)
		},
		setDebtReimNotelist({ commit, state }, name) {
			commit('setDebtReimNote', name)
		},
		setSaveDataBaoxiao({ commit, state }, name) {
			commit('setSaveDatBNote', name)
		},
		setOctDataList({ commit, state }, name) {
			commit('setOctDataNote', name)
		},
		setOverWorkList({ commit, state }, name) {
			// debugger
			commit('setOverWorkNote', name)
		},
		setSaveOverWork({ commit, state }, name) {
			commit('setSaveOverWork', name)
		},
		//设置字表
		setBaseData({ commit, state }, name) {
			commit('setBaseData', name)
		}
	},
	// 4. mutations
	mutations: {
		// state指的是state的数据
		// name传递过来的数据
		setInfo(state, name) {
			state.userInfo = name;
		},
		setTravalPage(state, name) {
			state.TravalPagelist = name;
		},
		setDebtReimNote(state, name) {
			state.DebtReimNotelist = name;
		},
		setSaveDatBNote(state, name) {
			state.SaveDataBaoxiao = name;
		},
		setOctDataNote(state, name) {
			state.OctDataList = name;
		},
		setOverWorkNote(state, name) {
			state.OverWorkList = name;
		},
		setSaveOverWork(state, name) {
			state.SaveOverWork = name;
		},

		//设置字表
		setBaseData(state, name) {
			state.BaseData = name;
		},

	}
});

export default store;
